(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 100;
    vc.extends({
        data: {
            userInfo: {}
        },
        _initMethod: function () {
            $that.initPersonalInfo();
        },
        _initEvent: function () {

        },
        methods: {
            initPersonalInfo: function () {
                let userInfo = vc.getData('/nav/getUserInfo');
                if (userInfo) {
                    let param = {
                        params: {
                            page: 1,
                            row: 1,
                            userId: userInfo.userId
                        }
                    }
                    vc.http.apiGet('user.listUser',
                        param,
                        function (json, res) {
                            var _userInfo = JSON.parse(json);
                            $that.userInfo = _userInfo.data[0];
                        }, function (errInfo, error) {
                            console.log('请求失败处理');
                        });
                }
            },
            savePersonalInfo: function () {
                if (!$that.updateUserValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    'user.updateUser',
                    JSON.stringify($that.userInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code === 0) {
                            vc.toast("保存成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            updateUserValidate() {
                return vc.validate.validate({
                    updateUserInfo: $that.userInfo
                }, {
                    'updateUserInfo.tel': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "手机号不能为空"
                        },
                        {
                            limit: "phone",
                            param: "",
                            errInfo: "手机号格式错误"
                        },
                    ],
                    'updateUserInfo.name': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "用户名不能为空"
                        },
                    ],
                    'updateUserInfo.userId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "用户ID不能为空"
                        },
                    ],
                });
            },
        }
    });

})(window.vc);